from sqlalchemy import create_engine, text, Column, Integer, String, Sequence
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

Base = declarative_base()


class T_user(Base):
    __tablename__ = 't_user'

    id = Column(Integer, Sequence('id'), primary_key=True)
    name = Column(String(64))
    gender = Column(String(64))
    age = Column(Integer)

    def __repr__(self):
        return "Product(id=%d, name=%s, gender=%s, age=%d)"(self.id, self.name, self.gender, self.age)


DB_CON_STR = 'mysql+pymysql://root:ut123456@localhost/testdatabase?charset=utf8mb4'
engine = create_engine(DB_CON_STR, echo=False)

DBSession = sessionmaker(bind=engine)
session = DBSession()

res = session.query(T_user).filter(text("id=1")).one()
print(res.id, res.name, res.gender)
